package com.testing.runner;

import com.testing.common.AutoTools;
import com.testing.common.ExcelReader;
import com.testing.common.ExcelWriter;
import com.testing.web.WebKeyword;
import org.apache.xmlbeans.impl.common.ResolverUtil;

import java.util.List;

/**
 * @Classname RunWithExcel
 * @Description 类型说明
 * @Date 2022/10/19 21:36
 * @Created by 特斯汀Roy
 */
public class RunWebDDT {
    public static void main(String[] args) {
        WebKeyword web = new WebKeyword();
        ExcelReader cases = new ExcelReader("Cases/WebCases.xlsx");
        //结果文件的复制生成
        ExcelWriter results = new ExcelWriter("Cases/WebCases.xlsx", "Cases/Result/webResult" + AutoTools.dateStr("yyyyMMdd-HH：mm") + ".xlsx");
        //遍历用例文件中的各个sheet页
        for (int sheetNO = 0; sheetNO < cases.getTotalSheetNo(); sheetNO++) {
            //操作当前的sheet页
            cases.useSheetByIndex(sheetNO);
            results.useSheetByIndex(sheetNO);
            for (int rowNO = 0; rowNO < cases.getRowNo(); rowNO++) {
                //读取每一行得到rowContent
                List<String> rowContent = cases.readLine(rowNO);
                System.out.println("当前行是" + rowNO + "信息是" + rowContent);
                //基于每一行执行测试用例,看第4列关键字列的内容进行决定
                boolean result = true;
                switch (rowContent.get(3)) {
                    case "openBrowser":
                        web.openBrowser(rowContent.get(4));
                        break;
                    case "visitWeb":
                        web.visitWeb(rowContent.get(4));
                        break;
                    case "input":
                        result = web.input(rowContent.get(4), rowContent.get(5));
                        break;
                    case "click":
                        result = web.click(rowContent.get(4));
                        break;
                    case "switchFrame":
                        web.switchFrame(rowContent.get(4));
                        break;
                    case "saveTimeStampParam":
                        web.saveDateParam(rowContent.get(4), rowContent.get(5), rowContent.get(6));
                        break;
                    case "selectByText":
                        web.selectByText(rowContent.get(4), rowContent.get(5));
                        break;
                    case "halt":
                        web.halt(rowContent.get(4));
                        break;
                    case "closeBrowser":
                        web.closeBrowser();
                        break;
                    case "assertDbExist":
                        result = web.assertDbExists(rowContent.get(4));
                        break;
                }
                //根据执行的结果判断写入的内容。
                if (result) {
                    results.writeCell(rowNO, 10, "测试成功");
                } else {
                    results.writeFailCell(rowNO, 10, "测试失败");
                }

            }
        }
        cases.close();
        results.save();


    }
}
